/**
 */
package OBSL.impl;

import OBSL.OBSLPackage;
import OBSL.QualityRelation;
import OBSL.RuleType;
import OBSL.Ruleset;
import OBSL.TemporalParameter;
import OBSL.TopLevelSituation;
import OBSL.TransitionRule;

import java.lang.reflect.InvocationTargetException;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.WrappedException;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Transition Rule</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link OBSL.impl.TransitionRuleImpl#getName <em>Name</em>}</li>
 *   <li>{@link OBSL.impl.TransitionRuleImpl#getRuleset <em>Ruleset</em>}</li>
 *   <li>{@link OBSL.impl.TransitionRuleImpl#getBefore <em>Before</em>}</li>
 *   <li>{@link OBSL.impl.TransitionRuleImpl#getAfter <em>After</em>}</li>
 *   <li>{@link OBSL.impl.TransitionRuleImpl#getComparisons <em>Comparisons</em>}</li>
 *   <li>{@link OBSL.impl.TransitionRuleImpl#getType <em>Type</em>}</li>
 *   <li>{@link OBSL.impl.TransitionRuleImpl#getDefiningLink <em>Defining Link</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TransitionRuleImpl extends MinimalEObjectImpl.Container implements TransitionRule {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getBefore() <em>Before</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBefore()
	 * @generated
	 * @ordered
	 */
	protected TopLevelSituation before;

	/**
	 * The cached value of the '{@link #getAfter() <em>After</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAfter()
	 * @generated
	 * @ordered
	 */
	protected TopLevelSituation after;

	/**
	 * The cached value of the '{@link #getComparisons() <em>Comparisons</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getComparisons()
	 * @generated
	 * @ordered
	 */
	protected EList<QualityRelation> comparisons;

	/**
	 * The default value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected static final RuleType TYPE_EDEFAULT = RuleType.CREATION;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected RuleType type = TYPE_EDEFAULT;

	/**
	 * The cached setting delegate for the '{@link #getDefiningLink() <em>Defining Link</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDefiningLink()
	 * @generated
	 * @ordered
	 */
	protected EStructuralFeature.Internal.SettingDelegate DEFINING_LINK__ESETTING_DELEGATE = ((EStructuralFeature.Internal)OBSLPackage.Literals.TRANSITION_RULE__DEFINING_LINK).getSettingDelegate();

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TransitionRuleImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return OBSLPackage.Literals.TRANSITION_RULE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.TRANSITION_RULE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Ruleset getRuleset() {
		if (eContainerFeatureID() != OBSLPackage.TRANSITION_RULE__RULESET) return null;
		return (Ruleset)eInternalContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRuleset(Ruleset newRuleset, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newRuleset, OBSLPackage.TRANSITION_RULE__RULESET, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRuleset(Ruleset newRuleset) {
		if (newRuleset != eInternalContainer() || (eContainerFeatureID() != OBSLPackage.TRANSITION_RULE__RULESET && newRuleset != null)) {
			if (EcoreUtil.isAncestor(this, newRuleset))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newRuleset != null)
				msgs = ((InternalEObject)newRuleset).eInverseAdd(this, OBSLPackage.RULESET__RULES, Ruleset.class, msgs);
			msgs = basicSetRuleset(newRuleset, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.TRANSITION_RULE__RULESET, newRuleset, newRuleset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TopLevelSituation getBefore() {
		return before;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBefore(TopLevelSituation newBefore, NotificationChain msgs) {
		TopLevelSituation oldBefore = before;
		before = newBefore;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, OBSLPackage.TRANSITION_RULE__BEFORE, oldBefore, newBefore);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBefore(TopLevelSituation newBefore) {
		if (newBefore != before) {
			NotificationChain msgs = null;
			if (before != null)
				msgs = ((InternalEObject)before).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - OBSLPackage.TRANSITION_RULE__BEFORE, null, msgs);
			if (newBefore != null)
				msgs = ((InternalEObject)newBefore).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - OBSLPackage.TRANSITION_RULE__BEFORE, null, msgs);
			msgs = basicSetBefore(newBefore, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.TRANSITION_RULE__BEFORE, newBefore, newBefore));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TopLevelSituation getAfter() {
		return after;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAfter(TopLevelSituation newAfter, NotificationChain msgs) {
		TopLevelSituation oldAfter = after;
		after = newAfter;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, OBSLPackage.TRANSITION_RULE__AFTER, oldAfter, newAfter);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAfter(TopLevelSituation newAfter) {
		if (newAfter != after) {
			NotificationChain msgs = null;
			if (after != null)
				msgs = ((InternalEObject)after).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - OBSLPackage.TRANSITION_RULE__AFTER, null, msgs);
			if (newAfter != null)
				msgs = ((InternalEObject)newAfter).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - OBSLPackage.TRANSITION_RULE__AFTER, null, msgs);
			msgs = basicSetAfter(newAfter, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.TRANSITION_RULE__AFTER, newAfter, newAfter));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TemporalParameter getDefiningLink() {
		return (TemporalParameter)DEFINING_LINK__ESETTING_DELEGATE.dynamicGet(this, null, 0, true, false);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TemporalParameter basicGetDefiningLink() {
		return (TemporalParameter)DEFINING_LINK__ESETTING_DELEGATE.dynamicGet(this, null, 0, false, false);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<QualityRelation> getComparisons() {
		if (comparisons == null) {
			comparisons = new EObjectContainmentEList<QualityRelation>(QualityRelation.class, this, OBSLPackage.TRANSITION_RULE__COMPARISONS);
		}
		return comparisons;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RuleType getType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(RuleType newType) {
		RuleType oldType = type;
		type = newType == null ? TYPE_EDEFAULT : newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.TRANSITION_RULE__TYPE, oldType, type));
	}

	/**
	 * The cached invocation delegate for the '{@link #otherLinks() <em>Other Links</em>}' operation.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #otherLinks()
	 * @generated
	 * @ordered
	 */
	protected static final EOperation.Internal.InvocationDelegate OTHER_LINKS__EINVOCATION_DELEGATE = ((EOperation.Internal)OBSLPackage.Literals.TRANSITION_RULE___OTHER_LINKS).getInvocationDelegate();

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	public EList<TemporalParameter> otherLinks() {
		try {
			return (EList<TemporalParameter>)OTHER_LINKS__EINVOCATION_DELEGATE.dynamicInvoke(this, null);
		}
		catch (InvocationTargetException ite) {
			throw new WrappedException(ite);
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case OBSLPackage.TRANSITION_RULE__RULESET:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetRuleset((Ruleset)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case OBSLPackage.TRANSITION_RULE__RULESET:
				return basicSetRuleset(null, msgs);
			case OBSLPackage.TRANSITION_RULE__BEFORE:
				return basicSetBefore(null, msgs);
			case OBSLPackage.TRANSITION_RULE__AFTER:
				return basicSetAfter(null, msgs);
			case OBSLPackage.TRANSITION_RULE__COMPARISONS:
				return ((InternalEList<?>)getComparisons()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case OBSLPackage.TRANSITION_RULE__RULESET:
				return eInternalContainer().eInverseRemove(this, OBSLPackage.RULESET__RULES, Ruleset.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case OBSLPackage.TRANSITION_RULE__NAME:
				return getName();
			case OBSLPackage.TRANSITION_RULE__RULESET:
				return getRuleset();
			case OBSLPackage.TRANSITION_RULE__BEFORE:
				return getBefore();
			case OBSLPackage.TRANSITION_RULE__AFTER:
				return getAfter();
			case OBSLPackage.TRANSITION_RULE__COMPARISONS:
				return getComparisons();
			case OBSLPackage.TRANSITION_RULE__TYPE:
				return getType();
			case OBSLPackage.TRANSITION_RULE__DEFINING_LINK:
				if (resolve) return getDefiningLink();
				return basicGetDefiningLink();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case OBSLPackage.TRANSITION_RULE__NAME:
				setName((String)newValue);
				return;
			case OBSLPackage.TRANSITION_RULE__RULESET:
				setRuleset((Ruleset)newValue);
				return;
			case OBSLPackage.TRANSITION_RULE__BEFORE:
				setBefore((TopLevelSituation)newValue);
				return;
			case OBSLPackage.TRANSITION_RULE__AFTER:
				setAfter((TopLevelSituation)newValue);
				return;
			case OBSLPackage.TRANSITION_RULE__COMPARISONS:
				getComparisons().clear();
				getComparisons().addAll((Collection<? extends QualityRelation>)newValue);
				return;
			case OBSLPackage.TRANSITION_RULE__TYPE:
				setType((RuleType)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case OBSLPackage.TRANSITION_RULE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case OBSLPackage.TRANSITION_RULE__RULESET:
				setRuleset((Ruleset)null);
				return;
			case OBSLPackage.TRANSITION_RULE__BEFORE:
				setBefore((TopLevelSituation)null);
				return;
			case OBSLPackage.TRANSITION_RULE__AFTER:
				setAfter((TopLevelSituation)null);
				return;
			case OBSLPackage.TRANSITION_RULE__COMPARISONS:
				getComparisons().clear();
				return;
			case OBSLPackage.TRANSITION_RULE__TYPE:
				setType(TYPE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case OBSLPackage.TRANSITION_RULE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case OBSLPackage.TRANSITION_RULE__RULESET:
				return getRuleset() != null;
			case OBSLPackage.TRANSITION_RULE__BEFORE:
				return before != null;
			case OBSLPackage.TRANSITION_RULE__AFTER:
				return after != null;
			case OBSLPackage.TRANSITION_RULE__COMPARISONS:
				return comparisons != null && !comparisons.isEmpty();
			case OBSLPackage.TRANSITION_RULE__TYPE:
				return type != TYPE_EDEFAULT;
			case OBSLPackage.TRANSITION_RULE__DEFINING_LINK:
				return DEFINING_LINK__ESETTING_DELEGATE.dynamicIsSet(this, null, 0);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
		switch (operationID) {
			case OBSLPackage.TRANSITION_RULE___OTHER_LINKS:
				return otherLinks();
		}
		return super.eInvoke(operationID, arguments);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", type: ");
		result.append(type);
		result.append(')');
		return result.toString();
	}

} //TransitionRuleImpl
